package com.ruoyi.orderEat.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.orderEat.domain.CategoryInfoVO;
import com.ruoyi.orderEat.domain.CommonDomain;
import com.ruoyi.orderEat.domain.WxShopVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.orderEat.domain.CategoryInfo;
import com.ruoyi.orderEat.service.ICategoryInfoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 商品分类Controller
 *
 * @author ruoyi
 * @date 2023-11-17
 */
@Api("商品分类管理")
@RestController
@RequestMapping("/orderEat/orderEat")
public class CategoryInfoController extends BaseController
{
    @Autowired
    private ICategoryInfoService categoryInfoService;

    /**
     * 查询商品分类列表
     */
    @ApiOperation("查询商品分类列表")
    @PreAuthorize("@ss.hasPermi('orderEat:orderEat:list')")
    @GetMapping("/list")
    public TableDataInfo list(CategoryInfo categoryInfo)
    {
        startPage();
        List<CategoryInfoVO> list = categoryInfoService.selectCategoryInfoVoList(categoryInfo);
        return getDataTable(list);
    }

    /**
     * 查询商品分类下拉选
     */
    @ApiOperation("查询商品分类下拉选")
    @PreAuthorize("@ss.hasPermi('orderEat:orderEat:list')")
    @GetMapping("/categoryList")
    public AjaxResult categoryList()
    {
        List<CategoryInfoVO> categoryInfoVOList = categoryInfoService.queryCategoryInfoVODropDown();
        return success(categoryInfoVOList);
    }

    /**
     * 小程序查询商品全量内容
     */
    @ApiOperation("小程序查询商品全量内容")
    @PreAuthorize("@ss.hasPermi({'orderEat:orderEat:list','wx'})")
    @GetMapping("/wxShopList")
    public AjaxResult wxShopList()
    {
        List<WxShopVO> wxShopVOS = categoryInfoService.queryWxShopVO();
        return success(wxShopVOS);
    }


    /**
     * 导出商品分类列表
     */
    @PreAuthorize("@ss.hasPermi('orderEat:orderEat:export')")
    @Log(title = "商品分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CategoryInfo categoryInfo)
    {
        List<CategoryInfo> list = categoryInfoService.selectCategoryInfoList(categoryInfo);
        ExcelUtil<CategoryInfo> util = new ExcelUtil<CategoryInfo>(CategoryInfo.class);
        util.exportExcel(response, list, "商品分类数据");
    }

    /**
     * 获取商品分类详细信息
     */
    @PreAuthorize("@ss.hasPermi('orderEat:orderEat:query')")
    @GetMapping(value = "/{categoryId}")
    public AjaxResult getInfo(@PathVariable("categoryId") Long categoryId)
    {
        return success(categoryInfoService.selectCategoryInfoByCategoryId(categoryId));
    }

    /**
     * 新增商品分类
     */
    @PreAuthorize("@ss.hasPermi('orderEat:orderEat:add')")
    @Log(title = "商品分类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CategoryInfo categoryInfo)
    {
        return toAjax(categoryInfoService.insertCategoryInfo(categoryInfo));
    }

    /**
     * 修改商品分类
     */
    @PreAuthorize("@ss.hasPermi('orderEat:orderEat:edit')")
    @Log(title = "商品分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CategoryInfo categoryInfo)
    {
        return toAjax(categoryInfoService.updateCategoryInfo(categoryInfo));
    }

    /**
     * 删除商品分类
     */
    @PreAuthorize("@ss.hasPermi('orderEat:orderEat:remove')")
    @Log(title = "商品分类", businessType = BusinessType.DELETE)
	@DeleteMapping("/{categoryIds}")
    public AjaxResult remove(@PathVariable Long[] categoryIds)
    {
        return toAjax(categoryInfoService.deleteCategoryInfoByCategoryIds(categoryIds));
    }
    /**
     * 上传图片
     */
    @Log(title = "商品分类", businessType = BusinessType.INSERT)
    @PostMapping("/upload")
    public AjaxResult uploadPicture(MultipartFile file)
    {
        return success(categoryInfoService.uploadPicture(file));
    }
    /**
     * 删除图片
     */
    @PreAuthorize("@ss.hasPermi('orderEat:orderEat:remove')")
    @Log(title = "删除图片", businessType = BusinessType.DELETE)
    @PostMapping("/removePicture")
    public AjaxResult removePicture(@RequestBody CommonDomain commonDomain)
    {
        categoryInfoService.deletePicture(commonDomain.getPicureUrl());
        return success();
    }

}
